package com.appspot.moviesessions.interfaces.webapp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.appspot.moviesessions.interfaces.webapp.dto.Assembler;
import com.appspot.moviesessions.interfaces.webapp.dto.Schedule;
import com.appspot.moviesessions.model.SessionRepository;

@Controller
public class SessionController {

	private SessionRepository repository;
	private Assembler assembler;

	@Autowired
	public SessionController(SessionRepository repository,
	        Assembler dtoAssembler) {
		this.repository = repository;
		this.assembler = dtoAssembler;

	}

	@RequestMapping(value = "/movies", method = RequestMethod.GET)
	public @ResponseBody
	Schedule getMovies() {
		return assembler.assemble(repository.getCurrentSessions());
	}

}
